package pro.lepers.portfolio {
	import pro.lepers.portfolio.view.Content;
	import pro.lepers.portfolio.view.Footer;
	import pro.lepers.portfolio.view.ScaledContainer;
	import pro.lepers.portfolio.view.header.Header;
	import pro.lepers.portfolio.view.header.Header_FC;
	import pro.lepers.portfolio.view.misc.Background;
	import pro.lepers.portfolio.view.misc.OverLayer;

	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	/**
	 * @author plepers
	 */
	public class Site extends Sprite {

		
		public function Site () {
			if( _instance != null ) throw new Error( "pro.lepers.portfolio.Site est deja instancié" );
			_instance = this;
			_build( );
			
			addEventListener( Event.ADDED_TO_STAGE, onAdded );
			addEventListener( Event.REMOVED_FROM_STAGE, onRemoved );
		}

		private function onAdded (event : Event) : void {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			stage.addEventListener( Event.RESIZE, onResize );
			onResize( );
		}

		private function onRemoved (event : Event) : void {
			stage.removeEventListener( Event.RESIZE, onResize );
		}

		private function onResize (event : Event = null ) : void {
			_scaledContainer.setSize( stage.stageWidth, stage.stageHeight );
			_background.setSize( stage.stageWidth, stage.stageHeight );
		}

		private function _build () : void {
			
			addChild( _scaledContainer = new ScaledContainer( ) );
			
			_scaledContainer.container.addChild( _background = new Background( ) );
			
			_scaledContainer.container.addChild( _header = new Header_FC( ) );

			_scaledContainer.container.addChild( _content = new Content( ) );
			
			_scaledContainer.container.addChild( _footer = new Footer( ) );

			
			addChild( OverLayer.start( ) );
		}

		
		private var _background : Background;

		private var _content : Content;

		private var _header : Header;

		private var _footer : Footer;

		private var _scaledContainer : ScaledContainer;

		
		private static var _instance : Site;

		
		
		
		public static function get background () : Sprite {
			return _instance._background;
		}

		public static function get scaledContainer () : Sprite {
			return _instance._scaledContainer;
		}
	}
}